package com.xgk.boot.module.core.controller.admin.truck;

import com.xgk.boot.framework.apilog.core.annotation.ApiAccessLog;
import com.xgk.boot.framework.common.constant.ErrorCodeConstants;
import com.xgk.boot.framework.common.exception.util.ServiceExceptionUtil;
import com.xgk.boot.framework.common.pojo.CommonResult;
import com.xgk.boot.framework.common.pojo.PageParam;
import com.xgk.boot.framework.common.pojo.PageResult;
import com.xgk.boot.framework.common.util.object.BeanUtils;
import com.xgk.boot.framework.excel.core.util.ExcelUtils;
import com.xgk.boot.framework.security.core.util.SecurityFrameworkUtils;
import com.xgk.boot.framework.translate.core.TranslateUtils;
import com.xgk.boot.module.core.controller.admin.truck.vo.*;
import com.xgk.boot.module.core.dal.dto.TruckOrderDto;
import com.xgk.boot.module.core.dal.entity.truck.*;
import com.xgk.boot.module.core.logistics.service.TruckOrderCommonService;
import com.xgk.boot.module.core.service.permission.UserRoleServiceImpl;
import com.xgk.boot.module.core.service.truck.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

import static com.xgk.boot.framework.apilog.core.enums.OperateTypeEnum.EXPORT;

@Tag(name = "管理后台 - 卡车订单服务商费用管理")
@RestController("adminTruckOrderServiceFeeController")
@RequestMapping("/system/truck-order/server-fee")
public class TruckOrderServiceFeeController {

    @Resource
    private TruckOrderServiceFeeServiceImpl truckOrderServiceFeeService;


    @PostMapping("/page")
    @Operation(summary = "分页获得订单服务商价格列表")
    @PreAuthorize("@ss.hasPermission('system:admin')")
    public CommonResult<PageResult<TruckOrderServiceFeeVO>> pageList(@Valid @RequestBody TruckOrderServiceFeeReqVO orderReqVO) {
//        Boolean currentUserAdmin = userRoleService.isCurrentUserAdmin();
//        if( !currentUserAdmin ) {
//            // 非管理员只能查询自己账号下订单
//            orderReqVO.setCustomerCode(SecurityFrameworkUtils.getLoginUser().getUsername());
//        }
        PageResult<TruckOrderServiceFeeVO> truckOrderServiceFeeVOPageResult = truckOrderServiceFeeService.pageTruckOrderServiceFeds(orderReqVO);
        return CommonResult.success(truckOrderServiceFeeVOPageResult);
    }


    @GetMapping("/get/{orderCode}")
    @Operation(summary = "获得订单服务商价格详情")
    @Parameter(name = "orderCode", description = "订单code", required = true, example = "1934923143484133377")
    @PreAuthorize("@ss.hasPermission('system:admin')")
    public CommonResult<TruckOrderServiceFeeVO> getOrderInfo(@PathVariable("orderCode") String orderCode) {
//        Boolean currentUserAdmin = userRoleService.isCurrentUserAdmin();
//        if( !currentUserAdmin && !truckOrdersService.checkOrderPermission(orderCode)) {
//            // 非管理员查询自己账号下订单,检查是有查询该订单的权限
//            throw ServiceExceptionUtil.exception(ErrorCodeConstants.COMMON_NO_PERMISSION, orderCode);
//        }
        TruckOrderServiceFeeDO serviceFeeByOrderCode = truckOrderServiceFeeService.getServiceFeeByOrderCode(orderCode);
        TruckOrderServiceFeeVO truckOrderServiceFeeVO = BeanUtils.toBean(serviceFeeByOrderCode, TruckOrderServiceFeeVO.class);
        return CommonResult.success(truckOrderServiceFeeVO);
    }
}
